<template>
	<view class="my-class-page">
		<view style="text-align: center;padding: 20px;" v-if="eventRegList.length == 0">暂无数据</view>
		<view class="list-area" v-for="item in eventRegList" :key="item._id" @click="toClassDetail(item)">
			<view class="list-top">
				<view class="">赛事名称：<view class="list-text text-title">{{item.title}}</view>
				</view>
				<view class="">赛事级别：<view class="list-text">{{item.raceTypeNm}}</view>
				</view>
			</view>
			<view class="list-top">
				<view class="">报名时间：
					<uni-dateformat class="list-text" style="width: 220px;display: inline-block;" 
						format="yyyy/MM/dd" :threshold="[0, 0]" :date="item.created_date"></uni-dateformat>
				</view>
				<view class="">报名人：<view class="list-text">{{item.created_by}}</view>
				</view>
			</view>
			<view style="position: absolute;right: 10px;top: 10px;">
				<view class="list-btn" :class="item.raceStatus == '报名中' ? 'is-pay':'no-pay'">
					{{item.raceStatus}}
				</view>
			</view>
		</view>
	</view>
	</view>
</template>

<script>
	const db = uniCloud.database()
	export default {
		data() {
			return {
				userInfo: {},
				eventRegList: [],
				competiton: {},
				obj: {}
			}
		},
		onLoad(e) {
			this.obj = e
		},
		onReady() {},
		onShow() {
			const _this = this
			this.getEventReg(this.obj)
			uni.getStorage({
				key: 'userInfo',
				success: function(res) {
					if (res.data) {
						_this.userInfo = res.data
					}
				},
				fail: function(res) {
					uni.navigateTo({
						url: '../login/login'
					});
				}
			})
		},
		created() {},
		mounted() {},
		methods: {
			getEventReg(e) {
				const where = `"ballTeamId"=="${e.id}"&&"deleted_at"==null`
				return db.collection('event-registration').where(where)
					.field('title,raceId,raceType,raceStatus,listEntries,created_date,created_by')
					.get().then((res) => {
						const data = res.result.data
						if (data) {
							const arr = []
							data.map(item => {
								item.raceTypeNm = item.raceType == 0 ? '公开组' : '职工组'
								arr.push(item)
							})
							this.eventRegList = arr
						}
						console.log(res)
					}).catch((err) => {
						uni.showModal({
							content: err.message || '请求服务失败',
							showCancel: false
						})
					})
			},
			toClassDetail(item) {
				const _this = this
				db.collection('competition-MGMT').doc(item.raceId).field(
					"regTime,raceTime,raceType,state,entryNum,participantsNum,raceAddress"
				).get().then((res) => {
					const data = res.result.data[0]
					if (data) {
						const parm = {
							id: data._id,
							typ: data.raceType,
							entryNum: data.entryNum,
							regTime: JSON.parse(data.regTime),
							participantsNum: data.participantsNum,
							raceTime: JSON.parse(data.raceTime),
							raceAddress: data.raceAddress,
							listEntries: item.listEntries,
							title: item.title,
							state: data.state
						}
						uni.navigateTo({
							url: `../competition/eventRegistration?parm=${JSON.stringify(parm)}`
						});
					}
				}).catch((err) => {
					uni.showModal({
						content: err.message || '请求服务失败',
						showCancel: false
					})
				}).finally(() => {})
			}
		}
	}
</script>

<style>
	.my-class-page {
		padding: 10px;
	}

	.list-area {
		height: 150px;
		border: 1px solid #fc993b;
		padding: 5px;
		margin-bottom: 20px;
		box-shadow: 1px 1px 2px 1px #fc993b;
		cursor: pointer;
		position: relative;
	}

	.list-top {
		display: flex;
		margin-bottom: 20px;
	}

	.list-top view {
		flex: 1;
	}

	.list-btn {
		text-align: center;
		width: 80px;
		height: 30px;
		line-height: 30px;
		color: #fff;
		display: inline-block;
	}

	.list-text {
		margin-top: 10px;
		color: #888;
	}

	.no-pay {
		background-color: darkred;
	}

	.is-pay {
		background-color: green;
	}
	.text-title {
		font-size: 15px;
		font-family: 600;
		width: 220px;
		overflow: hidden;
		text-overflow: ellipsis;
		white-space: nowrap;
	}
</style>
<style lang="scss">
</style>